package blackhouse_server;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import blackhouse_dao.student_dao;
import blackhouse_entity.student;

public class studentinfo_server
{
	student_dao	stu	= new student_dao();

	public List<student> studentinfo_server(String user, String code)
			throws SQLException
	{
		String sql = null;
		if (code.equals("0") || code.equals("10"))
		{
			sql = "select * from student where stuCode='" + user + "' ";
		} else if (code.equals("4"))
		{
			sql = "select * from student a LEFT JOIN classtable b ON a.`classID` = b.`id`";
		}
		return stu.show_student(sql, code);
	}

	public boolean changeinfo_server(int age, String QQ, String phone,
			String address, String classid, String ID)
	{
		String sql = "UPDATE student SET stuAge=" + age + ",stuQQ='" + QQ
				+ "',stuPhone='" + phone + "',stuAddress='" + address
				+ "',classID='" + classid + "' WHERE stuCode='" + ID + "'";
		if (stu.changeinfo(sql) > 0)
		{
			return true;
		} else
		{
			return false;
		}

	}

	public boolean delstu(String key) throws SQLException
	{
		String sql = "{call proc_delstu(?)}";
		List<Object> list = new ArrayList<Object>();
		list.add(key);
		return stu.addStudentInfo(sql, list);
	}

	public boolean insertstuinfo(String name, String sex, int age, String QQ,
			String phone, String address, int classid) throws SQLException
	{
		String sql = "{call proc_addStudent(?,?,?,?,?,?,?)}";
		List<Object> list = new ArrayList<Object>();
		list.add(name);
		list.add(age);
		list.add(sex);
		list.add(QQ);
		list.add(phone);
		list.add(address);
		list.add(classid);
		return stu.addStudentInfo(sql, list);
	}
}
